package demo5;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Author: Lenovo
 * @Date: 2024/5/23 0:09
 * @description:
 */
class Student implements Comparable<Student> {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {

    }
    public static void main2(String[] args) {
        Student[]students=new Student[3];
        students[0]=new Student("zhangsan",20);
        students[1]=new Student("lisi",10);
        students[2]=new Student("wangwu",19);
        AgeComparator ageComparator=new AgeComparator();
        NameComparator nameComparator=new NameComparator();
        System.out.println("排序前："+Arrays.toString(students));
        Arrays.sort(students,ageComparator);
        System.out.println("排序后："+Arrays.toString(students));
    }
    public static void main1(String[] args) {
        /*int a=10;
        int b=20;
        System.out.println(a==b);*/
        Student[]students=new Student[3];
        Student student1=new Student("zhangsan",8);
        Student student2=new Student("lisi",10);
        AgeComparator ageComparator=new AgeComparator();
        NameComparator nameComparator=new NameComparator();
       // Arrays.sort();
        //System.out.println(student1.compareTo(student2));
    }
}
